//加载当前日期
function loadDate(){
    var time = new Date();
    var myYear = time.getFullYear();
    var myMonth = time.getMonth() + 1;
    var myDay = time.getDate();
    if (myMonth < 10) {
        myMonth = "0" + myMonth;
    }
    document.getElementById("day_day").innerHTML = myYear + "." + myMonth + "."	+ myDay;
}

/**
 * 隐藏或者显示侧边栏
 *
 **/
function switchSysBar(flag){
    var side = $('#side');
    var left_menu_cnt = $('#left_menu_cnt');
    if( flag==true ){	// flag==true
        left_menu_cnt.show(500, 'linear');
        side.css({width:'280px'});
        $('#top_nav').css({width:'77%', left:'304px'});
        $('#main').css({left:'280px'});
    }else{
        if ( left_menu_cnt.is(":visible") ) {
            left_menu_cnt.hide(10, 'linear');
            side.css({width:'60px'});
            $('#top_nav').css({width:'100%', left:'60px', 'padding-left':'28px'});
            $('#main').css({left:'60px'});
            $("#show_hide_btn").find('img').attr('src', 'images/common/nav_show.png');
        } else {
            left_menu_cnt.show(500, 'linear');
            side.css({width:'280px'});
            $('#top_nav').css({width:'77%', left:'304px', 'padding-left':'0px'});
            $('#main').css({left:'280px'});
            $("#show_hide_btn").find('img').attr('src', 'images/common/nav_hide.png');
        }
    }
}

$(function(){
    loadDate();

    // 显示隐藏侧边栏
    $("#show_hide_btn").click(function() {
        switchSysBar();
    });
});

//菜单切换
$(function () {
    $("#TabPage2 li").click(function () {
        //1.取消选中效果
        $("#TabPage2 li").each(function (index,item) {
            $(item).removeClass("selected")
            $(item).find("img").prop("src","/images/common/"+(index+1)+ ".jpg");
        })
        //2.为当前的li添加selected样式
        $(this).addClass("selected");
        //3.以当前按钮所在的位置文件名前缀 1 凭借后缀 _hover.jsp--> 1_hover.jsp
        //4.将拼接好的文件副高当前li中的img元素
        var index = ($(this).index() + 1);
        $(this).find("img").prop("src","/images/common/" + index + "_hover.jpg");


        //修改模块图片
        $("#nav_module img").prop("src","/images/common/module_" + index+ ".png");

        //切换菜单菜单是,加载新的菜单数据
        initZtree($(this).data("rootmenu"))
    });
});

//ztree配置
var setting = {
    data:{
        simpleData:{
            enable: true
        }
    },
    callback:{
        onClick:function (event,treeId,treeNode) {
            //修改iframe的src属性
            if (treeNode.action) {
                $("#rightMain").prop("src", treeNode.action);
            }
            console.log(treeNode.name);
            if (treeNode){
                //主页面包屑
                $("#here_area").html("当前位置：系统&nbsp;>&nbsp;业务模块"+treeNode.getParentNode().name+"&nbsp;>&nbsp;"+treeNode.name)
            }else{
                $("#here_area").html("当前位置：系统&nbsp;>&nbsp;"+treeNode.name)
            }
        }
    },
    async:{
        enable:true,
        url:"systemMenu/loadMenuByParentSn.do",
        autoParam:["sn=parentSn"]
    }

};
//菜单数据

var zNodes ={
        //这个节点是否为父节点(isParent:true)默认问false
        "business":{id:1 ,pId:0,name:"业务模块"  ,isParent:true,sn:"business"},

        "system":{id:2 ,pId:0,name:"系统模块" ,isParent:true,sn:"system"},

        "charts": {id: 3, pId: 0, name: "报表模块",isParent:true,sn:"charts"},
    };



$(function () {
    //页面加载完成是默认显示菜单树
    initZtree("business");

});



function initZtree(modle) {
    $.fn.zTree.init($("#dleft_tab1"),setting,zNodes[modle]);

}


















